package small.common.core.constants;

import small.common.core.util.StringUtil;

import java.util.HashMap;
import java.util.Map;

public enum ConfigType {

    /**
     * config type is "properties".
     */
    PROPERTIES("properties"),

    /**
     * config type is "xml".
     */
    XML("xml"),

    /**
     * config type is "json".
     */
    JSON("json"),

    /**
     * config type is "text".
     */
    TEXT("text"),

    /**
     * config type is "html".
     */
    HTML("html"),

    /**
     * config type is "yaml".
     */
    YAML("yaml"),

    /**
     * not a real type.
     */
    UNSET("unset");

    private final String type;

    private static final Map<String, ConfigType> LOCAL_MAP = new HashMap();

    static {
        for (ConfigType configType : values()) {
            LOCAL_MAP.put(configType.getType(), configType);
        }
    }

    ConfigType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public static ConfigType getDefaultType() {
        return TEXT;
    }

    /**
     * check input type is valid.
     *
     * @param type config type
     * @return it the type valid
     */
    public static Boolean isValidType(String type) {
        if (StringUtil.isBlank(type)) {
            return false;
        }
        return null != LOCAL_MAP.get(type) ? true : false;
    }
}
